package cn.source.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.source.common.annotation.Log;
import cn.source.common.core.controller.BaseController;
import cn.source.common.core.domain.AjaxResult;
import cn.source.common.enums.BusinessType;
import cn.source.system.domain.SchoolPlan;
import cn.source.system.domain.SchoolPlanZk;
import cn.source.system.service.ISchoolPlanService;
import cn.source.system.service.ISchoolPlanZkService;
import cn.source.common.utils.poi.ExcelUtil;
import cn.source.common.core.page.TableDataInfo;

/**
 * 学校招生计划Controller
 * 
 * @author sourcebyte.vip
 * @date 2024-03-15
 */
@RestController
@RequestMapping("/system/schoolPlanZk")
public class SchoolPlanZkController extends BaseController
{
    @Autowired
    private ISchoolPlanZkService schoolPlanService;

    /**
     * 查询学校招生计划列表
     */
    @PreAuthorize("@ss.hasPermi('system:schoolPlan:list')")
    @GetMapping("/list")
    public TableDataInfo list(SchoolPlanZk schoolPlan)
    {
        startPage();
        List<SchoolPlanZk> list = schoolPlanService.selectSchoolPlanList(schoolPlan);
        return getDataTable(list);
    }
    
    /**
     * 查询学校招生计划列表
     */
    @PreAuthorize("@ss.hasPermi('system:schoolPlanCheck:list')")
    @GetMapping("/checkList")
    public TableDataInfo checkList(SchoolPlanZk schoolPlan)
    {
        startPage();
        List<SchoolPlanZk> list = schoolPlanService.selectSchoolPlanCheckList(schoolPlan);
        return getDataTable(list);
    }

    /**
     * 导出学校招生计划列表
     */
    @PreAuthorize("@ss.hasPermi('system:schoolPlan:export')")
    @Log(title = "学校招生计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SchoolPlanZk schoolPlan)
    {
        List<SchoolPlanZk> list = schoolPlanService.selectSchoolPlanList(schoolPlan);
        ExcelUtil<SchoolPlanZk> util = new ExcelUtil<SchoolPlanZk>(SchoolPlanZk.class);
        util.exportExcel(response, list, "学校招生计划数据");
    }

    /**
     * 获取学校招生计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:schoolPlan:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(schoolPlanService.selectSchoolPlanById(id));
    }

    /**
     * 新增学校招生计划
     */
    @PreAuthorize("@ss.hasPermi('system:schoolPlan:add')")
    @Log(title = "学校招生计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SchoolPlanZk schoolPlan)
    {
        return toAjax(schoolPlanService.insertSchoolPlan(schoolPlan));
    }
    
    /**
     * 新增学校招生计划
     */
    @GetMapping(value = "/fixData")
    public AjaxResult fixData()
    {
    	SchoolPlanZk schoolPlan=new SchoolPlanZk();
    	schoolPlan.setYear(2024);
    	List<SchoolPlanZk> list = schoolPlanService.selectSchoolPlanList(schoolPlan);
    	for(int i=0;i<list.size();i++) {
    		SchoolPlanZk schoolPlan2=list.get(i);
    		String km2=schoolPlan2.getKm2();
    		if(km2!=null&&!km2.equals("")) {
	    		if(km2.indexOf("＋")>0) {
	    			String[] km2Arr=km2.split("＋");
	    			if(km2Arr[0].equals("思想政治")) {
	    				schoolPlan2.setKm21("政治");
	    			}else {
	    				schoolPlan2.setKm21(km2Arr[0]);
	    			}
	    			if(km2Arr.length>1) {
	    				if(km2Arr[1].equals("思想政治")) {
		    				schoolPlan2.setKm22("政治");
		    			}else {
		    				schoolPlan2.setKm22(km2Arr[1]);
		    			}
	    			}
	    			if(km2Arr.length>2) {
	    				if(km2Arr[2].equals("思想政治")) {
		    				schoolPlan2.setKm23("政治");
		    			}else {
		    				schoolPlan2.setKm23(km2Arr[2]);
		    			}
	    			}
	    			schoolPlanService.updateSchoolPlan(schoolPlan2);
	    		}else {
	    			if(km2.equals("不限")) {
	    				
	    			}else {
		    			if(km2.equals("思想政治")) {
		    				schoolPlan2.setKm21("政治");
		    			}else {
		    				schoolPlan2.setKm21(km2);
		    			}
		    			schoolPlanService.updateSchoolPlan(schoolPlan2);
	    			}
	    		}
	    		
    		}
    	}
        return toAjax(1);
    }

    /**
     * 修改学校招生计划
     */
    @PreAuthorize("@ss.hasPermi('system:schoolPlan:edit')")
    @Log(title = "学校招生计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SchoolPlanZk schoolPlan)
    {
        return toAjax(schoolPlanService.updateSchoolPlan(schoolPlan));
    }

    /**
     * 删除学校招生计划
     */
    @PreAuthorize("@ss.hasPermi('system:schoolPlan:remove')")
    @Log(title = "学校招生计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(schoolPlanService.deleteSchoolPlanByIds(ids));
    }
}
